package br.com.pfm.dao.impl;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import br.com.pfm.dao.ClienteDao;
import br.com.pfm.persistence.model.Cliente;

@Repository
public class ClienteDaoImpl implements ClienteDao{

	@PersistenceContext(unitName="pfm")
    private EntityManager em;
	
	@Override
	public Cliente findCliente(String login, String senha) {
		
		 Query query = em
				.createQuery("SELECT c FROM Cliente as c where c.login = :pLogin and c.pass = :pSenha");
		 
		 query.setParameter("pLogin", login);
		 query.setParameter("pSenha", senha);
		
		try{
			Cliente cliente = (Cliente) query.getSingleResult();
			return cliente;
		}catch(NoResultException e){
			return null;
		}	
	}

}
